import 'package:environmental_les_app/common/style/colours.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

class InputDialog extends StatelessWidget {
  // 标题
  final String title;
  // 输入框提示文本
  final String hintText;
  // 输入框控制器
  final TextEditingController _controller = TextEditingController();

  // 确定回调返回输入内容
  final ValueChanged<String>? onConfirm;

  InputDialog(
      {super.key, required this.title, required this.hintText, this.onConfirm});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            vGap20,
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  title,
                  style: const TextStyle(
                      fontSize: 15,
                      fontWeight: FontWeight.w500,
                      color: Colours.textC4C),
                )
              ],
            ),
            const SizedBox(height: 20),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 10),
              margin: const EdgeInsets.symmetric(horizontal: 16),
              decoration: BoxDecoration(
                color: Colours.bgF2F3F5,
                borderRadius: BorderRadius.circular(6),
              ),
              child: TextField(
                controller: _controller,
                decoration: InputDecoration(
                    hintStyle: const TextStyle(
                        color: Colours.textC9CDD4, fontSize: 15),
                    hintText: hintText,
                    border: InputBorder.none),
              ),
            ),
            const SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                hGap16,
                Expanded(
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.white,
                      side: const BorderSide(color: Colours.textC5C7D3),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                    onPressed: () {
                      // 确认按钮逻辑
                      Navigator.of(context).pop();
                    },
                    child: const Text('取消',
                        style: TextStyle(color: Colours.textC4C)),
                  ),
                ),
                hGap10,
                Expanded(
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colours.appMain,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                    onPressed: () {
                      // 确认按钮逻辑
                      Navigator.of(context).pop();
                      onConfirm?.call(_controller.text);
                    },
                    child:
                        const Text('确认', style: TextStyle(color: Colors.white)),
                  ),
                ),
                hGap16,
              ],
            ),
            vGap10,
          ],
        ),
      ),
    );
  }
}
